package com.cty.web;

import com.cty.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Auther: com.cty
 * @Date: 2020/3/21 20:57
 * @Description:
 * @version: 1.0
 */
@WebServlet(name = "AddUserServlet", urlPatterns = "/add")
public class AddUserServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置编码格式
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        // 获取请求参数
        User user = new User();
        user.setName(req.getParameter("name"));
        user.setPwd(req.getParameter("pwd"));

        HttpSession session = req.getSession();
        session.setAttribute("user", user);

        resp.sendRedirect("/war/main.jsp");
    }
}
